

#include "gd32w51x.h"
#include "WatchDog.h"

void WatchDog_Start(uint32_t time_ms){
	//看门狗时钟源为32KHz
	uint32_t reload_value = time_ms * 32 / 128;
	//看门狗定时器最大0xFFF
	while(reload_value > 0xFFF){

	}
	
    rcu_osci_on(RCU_IRC32K);
    /* wait till IRC32K is ready */
    while(SUCCESS != rcu_osci_stab_wait(RCU_IRC32K)){
    }  
    /* confiure FWDGT counter clock: 32KHz(IRC32K) / 128 = 0.25 KHz */
    fwdgt_config(reload_value, FWDGT_PSC_DIV128);  
    /* after 16 seconds to generate a reset */
    fwdgt_enable();
}

void WatchDog_Reset(void){
	fwdgt_counter_reload();
}

